<meta charset="utf-8">
<script type="text/javascript">
function saveRule(a) {
	var detailDiv = $(a).parent().parent();
	var ruleName = detailDiv.find(".ruleName").val();
	var keywords = "";
	detailDiv.find(".keywordItems li").each(function () {
		keywords += $(this).find(".val").html() + "#";
	});
	var ruleMsg = detailDiv.find(".ruleMessage").val();
	var ruleId = detailDiv.find(".ruleId").val();
	var msgid=detailDiv.find('.msgs .current').attr("id");
	var type=detailDiv.find('.role_list .selected').attr('type');
	if(type=='message'){
		ruleMsg=msgid;
	}
	$.ajax({url:"{:U('Reply/saveRule')}?t="+(new Date()), type:"post", data:{"id":ruleId,'type':type, "name":ruleName, "keyword":keywords, "context":ruleMsg}, dataType:"json", success:function (data) {
		if (data.success) {
			initRuleList();
			showMessage(Message.SaveSuccess,MessageType.OK);
		}
	}});
}
function delRule(a){
	var detailDiv = $(a).parent().parent();
	var ruleId=detailDiv.find('.ruleId').val();
	if(ruleId!=0){
		$.ajax({
			url:"{:U('Reply/deleteRule')}?t="+(new Date())+"&id="+ruleId,
			dataType:'json',
			success:function(data){
				if(data.success){
					detailDiv.parent().remove();
					showMessage(Message.DeleteSuccess,MessageType.OK);
				}else{
					showMessage(Message.DeleteFaild,MessageType.ERROR);
				}
			}
		});
	}else{
		$('#newRule').click();
	}
}
</script>
<div class="float-p" style="margin: 10px 0;">
	<button id="newRule" class="btnGrayS right" style="margin-right: 0;">
		添加规则
	</button>
</div>
<ul id="listContainer">
	<li id="listItemNew" class="ruleItem ruleItemEditing none">
		<div class="title">
			<div class="left">
				<h4>
					<span class="b">新规则</span>
				</h4>
			</div>
			<div class="right">

			</div>
			<div class="clr"></div>
		</div>
		<div class="detail float-p">
			<div class="cLine ruleNameWrap">
				<label class="c-g9">
					规则名：
					<input class="txtInput ruleName" type="text" value="asd"
						maxlength="60" name="privateRule.name">
					<input class='ruleId' value="0" type="hidden">

				</label>
				<span class="c-g9" style="padding-left: 10px;">规则名最多60个字</span>
			</div>
			<div class="float-p">
				<div class="left keywordsList">
					<div class="cLine header">
						<span class="left b">关键字</span>
					</div>
					<ul class="keywordItems">
					</ul>
					<div class="btnArea float-p">
						<a class="addKeyword btnGreenS right"> 添加关键字 </a>
						<a class="delKeyword btnRed left"> 删除选中 </a>
					</div>
				</div>
				<div class="replyList">
					<div id="ivrSettingArea" class="role_list">
							<div class="msgSenderPlugin">
								<input type="hidden" name="type">
								<input type="hidden" name="context">
								<ul class="tab">
									<li class=" chooseMedia selected" type='text' pane="pane1">
										<a>文字</a>
									</li>
									<!--  	<li class="chooseMedia vioce chooseMedia3" data-type="3">
										语音
									</li>
									<li class="chooseMedia chooseMedia2" data-type="2">
										图片
									</li>
									<li class="chooseMedia chooseMedia4" data-type="4">
										视频
									</li>-->
									<li class="chooseMedia "  type='message' pane="pane2">
										<a>图文消息</a>
									</li>
								</ul>
								<div class="panel" id='pane1' >
									<div class="txtArea">
										<div class="functionBar">
											<div class="tip">
												还可以输入
												<span class="b i">300</span> 字
											</div>
											<div class="clr"></div>
										</div>
										<div class="editArea">
											<textarea id="messageReply" maxLength=300
											 onkeyup="setWordsLimit(this)"float-p></textarea>
										</div>
									</div>
									<div class="mediaArea none" style="display: none;">
									</div>
								</div>
								<div class="panel"  id='pane2' style="display: none">
									<div class="txtArea" style="background: #fff">
									<div class='msgs'  style="padding: 5px">
									    <volist name="graphics" id="gra">
											<div class="appmsg " id="{$gra.id}" >
											    <volist name="gra['articles']" id="art">
													<if condition="$i eq 0">
														<div class='item'>
														<div class="appmsg_content">
															<h4 class="appmsg_title">{$head_title }</h4>
															<div class="appmsg_info">
																<em class="appmsg_date"></em>
															</div>
															<div class="appmsg_thumb_wrp">
																<img src="{:U('File/downLoad')}/id/{$art.img_id}"	style="width: 310px;height: 160px" class="appmsg_thumb">
															</div>
															<p class="appmsg_desc">{$summary}</p>
														</div>
														 
													</div>
													<else />
														<div id="appmsgItem2" class="appmsg_item js_appmsg_item " data-id="3" data-fileid="">
															<img class="js_appmsg_thumb appmsg_thumb" src="{:U('File/downLoad')}/id/{$art.img_id}">
															<h4 class="appmsg_title" >
																<a target="_blank" href="javascript:void(0);" onclick="return false;">{$head_title}</a>
															</h4>
														</div>
													</if>
												</volist>
												<img src='__PUBLIC__/img/big_sel.png' class='sel'>
											</div>
										</volist>
									</div>
									</div>
									 
								</div>
							</div>
						<div class="mask"></div>
					</div>
				</div>
			</div>
			<div class="btnArea float-p operator">
				<a class="delRule btnRed right" style="margin-left: 12px"
					onclick="delRule(this)"> 删除规则 </a>
				<a class="saveRule right btnGreenS" onclick="saveRule(this)">
					保存规则 </a>
			</div>
		</div>
	</li>
	<volist name="ruleList" id="rule">
		<li class="ruleItem" data-ruleid="{$rule.id}">
			<div class="title">
				<div class="left">
					<h4>
						<span class="b">规则{$i+1}:</span>
						<span class="n headerRuleName">{$rule.name}</span>
					</h4>
				</div>
				<div class="right">
					<a class="unfold c-b" href="javascript:;">展开</a>
					<a class="pickup c-b" href="javascript:;">收起</a>
				</div>
				<div class="clr"></div>
			</div>
			<div class="settingPre">
				<div class="preBox float-p">
					<label class="b">
						关键词：
					</label>
					<ul class="items keywordsPre">
						<volist name="rule[keywordList]" id="kw">
							<li class="item">
								{$kw}
							</li>
						</volist>
					</ul>
				</div>
				<div class="preBox float-p">
					<label class="b">
						回复：
					</label>
					<p class="items replyPre">
						{$rule.context}
					</p>
				</div>
			</div>
			<div class="detail float-p">
			<div class="cLine ruleNameWrap">
				<label class="c-g9">
					规则名：
					<input class="txtInput ruleName" type="text" value="asd"
						maxlength="60" name="privateRule.name">
					<input class='ruleId' value="${id}" type="hidden">

				</label>
				<span class="c-g9" style="padding-left: 10px;">规则名最多60个字</span>
			</div>
			<div class="float-p">
				<div class="left keywordsList">
					<div class="cLine header">
						<span class="left b">关键字</span>
					</div>
					<ul class="keywordItems">
					    <volist name="rule[keywordList]" id="kw">
							<li class="item float-p">
							<label class="left">
							<input class="left" type="checkbox">
							<div class="val left">{$kw}</div>
						 	</label>
							<a class="keywordEditor oh z c-opr" onclick="editKeyword(this)" >编辑</a></li>
						</volist>
					</ul>
					<div class="btnArea float-p">
						<a class="addKeyword btnGreenS right"> 添加关键字 </a>
						<a class="delKeyword btnRed left"> 删除选中 </a>
					</div>
				</div>
				<div class="replyList">
					
					<div id="ivrSettingArea" class="role_list">
							<div class="msgSenderPlugin">
								<input type="hidden" name="type">
								<input type="hidden" name="context">
								<ul class="tab">
									<li class=" chooseMedia ${rule.type=='text'?'selected':''}" type='text' pane="pane1">
										<a>文字</a>
									</li>
									<!--  	<li class="chooseMedia vioce chooseMedia3" data-type="3">
										语音
									</li>
									<li class="chooseMedia chooseMedia2" data-type="2">
										图片
									</li>
									<li class="chooseMedia chooseMedia4" data-type="4">
										视频
									</li>-->
									<li class="chooseMedia ${rule.type=='message'?'selected':''}"  type='message' pane="pane2">
										<a>图文消息</a>
									</li>
								</ul>
								<if condition="($rule.type eq text)">
								<div class="panel" id='pane1' style="display:block">
								<else/>
								<div class="panel" id='pane1' style="display: none">
								</if>
									<div class="txtArea">
										<div class="functionBar">
											<div class="tip">
												还可以输入
												<span class="b i">300</span> 字
											</div>
											<div class="clr"></div>
										</div>
										<div class="editArea">
											<textarea id="messageReply" maxLength=300
											 onkeyup="setWordsLimit(this)"  class="ruleMessage"> <if condition="$rule.type eq text">{$rule.contex}</if></textarea>
										</div>
									</div>
									<div class="mediaArea none" style="display: none;">
									</div>
								</div>
								<if condition="$rule.type eq text"> 
								<div class="panel"  id='pane2' style="display:  none}">
								<else/>
								<div class="panel"  id='pane2' style="display:block">
								</if>
									<div class="txtArea" style="background: #fff">
									<div class='msgs' style="padding: 5px">
									 <volist name="graphics" id="gra">
											<div class="appmsg " id="{$gra.id}" >
											    <volist name="gra['articles']" id="art">
											        <if condition="$i eq 0">
														<div class='item'>
														<div class="appmsg_content">
															<h4 class="appmsg_title">{$head_title }</h4>
															<div class="appmsg_info">
																<em class="appmsg_date"></em>
															</div>
															<div class="appmsg_thumb_wrp">
																<img src="{:U('File/downLoad')}/id/{$art.img_id}"	style="width: 310px;height: 160px" class="appmsg_thumb">
															</div>
															<p class="appmsg_desc">{$summary} </p>
														</div>
													    </div>
													<else/>
														<div id="appmsgItem2" class="appmsg_item js_appmsg_item " data-id="3" data-fileid="">
															<img class="js_appmsg_thumb appmsg_thumb" src="{:U('File/downLoad')}/id/{$art.img_id}">
															<h4 class="appmsg_title" >
																<a target="_blank" href="javascript:void(0);" onclick="return false;">{$head_title}</a>
															</h4>
														</div>
													</if>
												<img src='__PUBLIC__/img/big_sel.png' class='sel'>
											</div>
										</volist>
									</div>
									</div>
								</div>
							</div>
						<div class="mask"></div>
					</div>
				</div>
			</div>
			<div class="btnArea float-p operator">
				<a class="delRule btnRed right" style="margin-left: 12px"
					onclick="delRule(this)"> 删除规则 </a>
				<a class="saveRule right btnGreenS" onclick="saveRule(this)">
					保存规则 </a>
			</div>
		</div>
		</li>
	</volist>
</ul>
<div class="mask"></div>